package com.iuhao.orange.constants;

import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import static com.iuhao.orange.constants.Constants.CustomerTypeEnum.*;
import static com.iuhao.orange.constants.Constants.EducationEnum.*;
import static com.iuhao.orange.constants.Constants.LoanPeriodEnum.*;
import static com.iuhao.orange.constants.Constants.MarriageEnum.*;
import static com.iuhao.orange.constants.Constants.Status.*;

/**
 * Created by yanhao on 2018/5/7.
 */
public class Constants {

    public final static int DEFAULT_PAGE_MAX_ROWS = 200;

    public static final String ACCESS_TOKEN_MANAGEMENT = "ACCESS_TOKEN_MANAGEMENT_NEW:";
    public static final String ACCOUNT_INFO_MANAGEMENT = "ACCOUNT_INFO_MANAGEMENT_NEW:";
    public final static int DEFAULT_SMSCODE_EXPIRE_MINUTES = 10;

    /**
     * 葫芦侠 无抵押订单状态
     */
    public enum OrderStatusEnum {
        REFUSE(0, "审核拒绝"),
        APPLYING(1, "申请中"),
        FIRST_TRIAL(2, "初审"),
        WAIT_SIGNATURE(3, "待签合同"),
        SIGNATURE_ING(4, "签合同中"),
        SIGNATURE_ED(5, "已签合同"),
        LOAN_ED(6, "已放款"),
        REPAYMENTS(7, "还款中");

        private Integer code;
        private String desc;

        OrderStatusEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return desc;
        }
    }

    /**
     * 抵押贷订单状态
     */
    public enum MortgageOrderStatusEnum {
        REFUSE(0, "审核拒绝"),
        APPLYING(1, "申请中"),
        CHECK_ING(2, "审核中"),
        CHONGBU_ING(3, "重补资料"),
        CHECK_MONEY(4, "审核金额"),
        WAIT_SIGN(5, "待签约"),
        FINISH_SIGN(50, "已签约"),
        WAIT_SIGNATURE(6, "待公证"),
        SIGNATURE_ING(60, "已公证"),
        SIGNATURE_ED(7, "待放款"),
        LOAN_ED(70, "已放款"),
        REPAYMENTS(8, "还款中");

        private Integer code;
        private String desc;

        MortgageOrderStatusEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return desc;
        }
    }


    public enum MortgageOrderApplyStep {
        BASE_INFO_STEP(10, "基本信息"),
        HOUSE_INFO_STEP(20, "房产信息"),
        SPOSE_INFO_STEP(30, "担保人信息"),
        ATTACH_INFO_STEP(40, "附件信息"),
        FINISH_INFO_STEP(50, "附件信息");

        private int code;
        private String desc;

        MortgageOrderApplyStep(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getName() {
            return desc;
        }
    }


    /**
     * 状态(征信报告状态,征信申请状态,预审状态)
     */
    public enum Status {
        VALID(1, "有效/成功"),//有效  成功
        INVALID(0, "无效/失败"),//无效 失败
        FAILURE(-1, "无效/失败"),
        SUCCESS(2, "有效/成功");
        private int code;
        private String desc;

        Status(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

    private static final Map<Object, String> statusMap = new HashMap<Object, String>() {{
        put(VALID.getCode(), VALID.getDesc());
        put(INVALID.getCode(), INVALID.getDesc());
        put(FAILURE.getCode(), FAILURE.getDesc());
        put(SUCCESS.getCode(), SUCCESS.getDesc());
    }};

    public static String getStatusNameByVbsCode(Integer vbsCode) {
        if (StringUtils.isEmpty(vbsCode)) {
            return "";
        }
        Set<Object> vbsCodes = statusMap.keySet();
        for (Object code : vbsCodes) {
            if (code.equals(vbsCode)) {
                return statusMap.get(vbsCode);
            }
        }
        return "";
    }


    /**
     * 订单申请步骤
     */

    public enum OrderApplyStepEnum {
        STEP_BASEINFO_PAGE(10, "基本信息页面"),
        STEP_IDCARD_PAGE(100, "身份认证"),
        STEP_HOUSE_PAGE(200, "房产信息认证"),
        STEP_CREDIT_PAGE(300, "征信信息页面"),
        STEP_LOAN_CHECK_CASH(400, "提现审核中页面"),
        STEP_LOAN_FAILURE_CASH(500, "审核拒绝页面"),
        STEP_LOAN_SUCCESS_CASH(600, "审核通过页面");
        private Integer code;
        private String desc;

        OrderApplyStepEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
    }

    /**
     * 性别
     */
    public enum SexEnum {
        MALE(1, "男"),
        FEMALE(2, "女");

        private Integer code;
        private String desc;

        SexEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getDesc() {
            return desc;
        }

    }

    // 1 无门店
    // 2 身份证校验
    // 3 获取额度失败
    // 5 非本地籍 无社保
    // 7 女 本地籍 无社保 征信空白
    // 8 男 无社保

    // 订单失败原因原因
    public enum OrderFailedReason {
        NOSTORE(1, "所在地区无门店"),
        IDCART(2, "VBS身份证校验失败"),
        PREREVIEW(3, "获取额度失败"),
        NOSOCIAL(5, "未缴社保公积金"),
        NOSOCIALCITY(6, "未找到社保公积金城市"),
        NOCREDIT(7, "征信空白并且没有社保"),
        MANWITHNOSIAL(8, "男且无社保"),
        AGE_NOT_MATCHES(9, "年龄不符合贷款要求");

        private Integer code;
        private String desc;

        OrderFailedReason(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return desc;
        }
    }

    // 婚姻状况
    public enum MarriageEnum {
        UNMARRIED("NEWMARRIAGE/WH", "未婚"),
        MARRIED("NEWMARRIAGE/YH", "已婚"),
        DIVORCE("NEWMARRIAGE/LH", "离婚"),
        WIDOWED("NEWMARRIAGE/SO", "丧偶");

        private String vbsCode;
        private String desc;

        MarriageEnum(String vbsCode, String desc) {
            this.vbsCode = vbsCode;
            this.desc = desc;
        }

        public String getVbsCode() {
            return vbsCode;
        }

        public String getName() {
            return desc;
        }
    }


    // 学历状况
    public enum EducationEnum {
        MASTER("NEWEDUCATION/SSJYS", "硕士及以上"),
        UNDERGRADUATE("NEWEDUCATION/BK", "本科"),
        JUNIOR_COLLEGE("NEWEDUCATION/DZ", "大专"),
        SENIOR_HIGH_SCHOOL("NEWEDUCATION/GZ", "高中"),
        TECHNICAL_SCHOOL("NEWEDUCATION/JX", "技校"),
        TECHNICAL_SECONDARY_SCHOOL("NEWEDUCATION/ZZ", "中专"),
        JUNIOR_HIGH_SCHOOL("NEWEDUCATION/CZ", "初中"),
        ELEMENTARY_SCHOOL("NEWEDUCATION/XX", "小学"),
        OTHER("NEWEDUCATION/QT", "其他");

        private String vbsCode;
        private String desc;

        EducationEnum(String vbsCode, String desc) {
            this.vbsCode = vbsCode;
            this.desc = desc;
        }

        public String getVbsCode() {
            return vbsCode;
        }

        public String getName() {
            return desc;
        }
    }


    /**
     * 客户类型
     */
    public enum CustomerTypeEnum {
        SHANGBANZU("JOBONLINE/SHANGBANZU", "上班族"),
        QIYELAOBAN("JOBONLINE/QIYELAOBAN", "企业老板"),
        SIYINGYEZHU("JOBONLINE/SIYINGYEZHU", "私营业主"),
        QITA("JOBONLINE/QITA", "其他");

        private String vbsCode;
        private String desc;

        CustomerTypeEnum(String vbsCode, String desc) {
            this.vbsCode = vbsCode;
            this.desc = desc;
        }

        public String getVbsCode() {
            return vbsCode;
        }

        public String getName() {
            return desc;
        }
    }


    /**
     * 预审 学历参数
     */

    public static Map<String, String> EducationMaps1 = new HashMap<String, String>() {{
        put("NEWEDUCATION/SSJYS", "10");
        put("NEWEDUCATION/BK", "20");
        put("NEWEDUCATION/DZ", "30");
        put("NEWEDUCATION/GZ", "60");
        put("NEWEDUCATION/JX", "50");
        put("NEWEDUCATION/ZZ", "40");
        put("NEWEDUCATION/CZ", "70");
        put("NEWEDUCATION/XX", "80");
        put("NEWEDUCATION/QT", "99");
    }};
    public static Map<String, String> MarriagePreviewMaps = new HashMap<String, String>() {{
        put("NEWMARRIAGE/WH", "10");
        put("NEWMARRIAGE/YH", "20");
        put("NEWMARRIAGE/LH", "40");
        put("NEWMARRIAGE/SO", "30");
        put("NEWMARRIAGE/WSMHYZK", "90");
    }};


    public static Map<Integer, String> ApplyLoanPeriodMaps = new HashMap<Integer, String>() {{
        put(3, "LOANPERIOD/SAN");
        put(6, "LOANPERIOD/LIU");
        put(9, "LOANPERIOD/JIU");
        put(12, "LOANPERIOD/SHIER");
    }};

    /**
     * 最高学历  -- 预审信息
     */

    public static Map<String, String> EducationMaps = new HashMap<String, String>() {{
        put("NEWEDUCATION/SSJYS", "3");
        put("NEWEDUCATION/BK", "4");
        put("NEWEDUCATION/DZ", "0");
        put("NEWEDUCATION/GZ", "0");
        put("NEWEDUCATION/JX", "0");
        put("NEWEDUCATION/ZZ", "0");
        put("NEWEDUCATION/CZ", "0");
        put("NEWEDUCATION/XX", "0");
        put("NEWEDUCATION/QT", "9");

    }};


    public static Map<String, String> educationMaps = new HashMap<String, String>() {{
        EducationEnum[] educationEnumValues = EducationEnum.values();
        for (EducationEnum educationEnum : educationEnumValues) {
            put(educationEnum.getVbsCode(), educationEnum.getName());
        }
    }};


    private static final Map<Object, String> dictionaries = new HashMap<Object, String>() {{
        // 婚姻
        put(UNMARRIED.getVbsCode(), UNMARRIED.getName());
        put(MARRIED.getVbsCode(), MARRIED.getName());
        put(DIVORCE.getVbsCode(), DIVORCE.getName());
        put(WIDOWED.getVbsCode(), WIDOWED.getName());

        // 学历
        put(MASTER.getVbsCode(), MASTER.getName());
        put(UNDERGRADUATE.getVbsCode(), UNDERGRADUATE.getName());
        put(JUNIOR_COLLEGE.getVbsCode(), JUNIOR_COLLEGE.getName());
        put(SENIOR_HIGH_SCHOOL.getVbsCode(), SENIOR_HIGH_SCHOOL.getName());
        put(TECHNICAL_SCHOOL.getVbsCode(), TECHNICAL_SCHOOL.getName());
        put(TECHNICAL_SECONDARY_SCHOOL.getVbsCode(), TECHNICAL_SECONDARY_SCHOOL.getName());
        put(JUNIOR_HIGH_SCHOOL.getVbsCode(), JUNIOR_HIGH_SCHOOL.getName());
        put(ELEMENTARY_SCHOOL.getVbsCode(), ELEMENTARY_SCHOOL.getName());
        put(OTHER.getVbsCode(), OTHER.getName());

        //客户类型
        put(SHANGBANZU.getVbsCode(), SHANGBANZU.getName());
        put(QIYELAOBAN.getVbsCode(), QIYELAOBAN.getName());
        put(SIYINGYEZHU.getVbsCode(), SIYINGYEZHU.getName());
        put(QITA.getVbsCode(), QITA.getName());

    }};

    public static String getDisplayNameByVbsCode(String vbsCode) {
        if (StringUtils.isEmpty(vbsCode)) {
            return "";
        }
        Set<Object> vbsCodes = dictionaries.keySet();
        for (Object code : vbsCodes) {
            if (code.equals(vbsCode)) {
                return dictionaries.get(vbsCode);
            }
        }
        return "";
    }


    /**
     * 贷款期限
     * <p>
     * 1	LOANPERIOD/YI
     * 3	LOANPERIOD/SAN
     * 6	LOANPERIOD/LIU
     * 7	LOANPERIOD/QITIAN
     * 9	LOANPERIOD/JIU
     * 12	LOANPERIOD/SHIER
     * 18	LOANPERIOD/SHIBA
     * 24	LOANPERIOD/ERSHISI
     * 36	LOANPERIOD/SANSHILIU
     * 48	LOANPERIOD/SISHIBA
     * 60	LOANPERIOD/LIUSHI
     */
    public enum LoanPeriodEnum {
        YI(1, "LOANPERIOD/YI"),
        SAN(3, "LOANPERIOD/SAN"),
        LIU(6, "LOANPERIOD/LIU"),
        QITIAN(7, "LOANPERIOD/QITIAN"),
        JIU(9, "LOANPERIOD/JIU"),
        SHIER(12, "LOANPERIOD/SHIER"),
        SHIBA(18, "LOANPERIOD/SHIBA"),
        ERSHISI(24, "LOANPERIOD/ERSHISI"),
        SANSHILIU(36, "LOANPERIOD/SANSHILIU"),
        SISHIBA(48, "LOANPERIOD/SISHIBA"),
        LIUSHI(60, "LOANPERIOD/LIUSHI");

        private Integer period;
        private String vbsCode;

        LoanPeriodEnum(Integer period, String vbsCode) {
            this.period = period;
            this.vbsCode = vbsCode;
        }

        public Integer getPeriod() {
            return period;
        }

        public String getVbsCode() {
            return vbsCode;
        }
    }

    private static final Map<Integer, String> loanPeriods = new HashMap<Integer, String>() {{

        // 贷款期限
        put(YI.getPeriod(), YI.getVbsCode());
        put(SAN.getPeriod(), SAN.getVbsCode());
        put(LIU.getPeriod(), LIU.getVbsCode());
        put(QITIAN.getPeriod(), QITIAN.getVbsCode());
        put(JIU.getPeriod(), JIU.getVbsCode());
        put(SHIER.getPeriod(), SHIER.getVbsCode());
        put(SHIBA.getPeriod(), SHIBA.getVbsCode());
        put(ERSHISI.getPeriod(), ERSHISI.getVbsCode());
        put(SANSHILIU.getPeriod(), SANSHILIU.getVbsCode());
        put(SISHIBA.getPeriod(), SISHIBA.getVbsCode());
        put(LIUSHI.getPeriod(), LIUSHI.getVbsCode());

    }};

    public static String getVbsLoanPeriodCode(Integer period) {
        Set<Integer> periods = loanPeriods.keySet();
        for (Integer num : periods) {
            if (num.equals(period)) {
                return loanPeriods.get(period);
            }
        }
        return SANSHILIU.getVbsCode();
    }

    public static Integer getPeriodNum(String vbsCode) {
        Set<Integer> periods = loanPeriods.keySet();
        for (Integer num : periods) {
            if (loanPeriods.get(num).equals(vbsCode)) {
                return num;
            }
        }
        return SANSHILIU.getPeriod();
    }

    //账单状态：1、未还，2、部分还款，3、全额还款
    public enum LoanStatus {
        NO_PAY(1, "未还"),
        All_PAY(3, "全额还款"),
        OVER_PAY(4, "逾期");

        private int code;
        private String desc;

        LoanStatus(Integer code, String desc) {
            this.desc = desc;
            this.code = code;
        }

        public int getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
    }

    /**
     * 银行卡type类型 银行卡类型（1，借记卡； 2，信用卡）
     */
    public final static int BANKCARD_TYPE_JJ = 1;


    public final static int BANKCARD_TYPE_XY = 2;
    /**
     * 借记卡(储蓄卡)卡号长度19  信用卡卡号长度16  银行卡分银行中信 招商 卡号不一样
     */
    public final static int BANKCARD_LENGTH_JJ = 19;

    public final static int BANKCARD_LENGTH_XY = 16;


    //账单状态：1、已结清，0、未结清，-1、预清贷
    public enum IsCleanLoanStatus {
        NO_CLEAN(0, "未结清"),
        All_CLEAN(1, "已结清"),
        ING_CLEAN(-1, "预清贷");

        private int code;
        private String desc;

        IsCleanLoanStatus(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public int getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
    }

}

